// 测试链接 : https://www.luogu.com.cn/problem/P1525
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

class Main {
	int n, m;
	vector<int> ent;
	vector<int> father;
	vector<vector<int>> rel;

	int find(int x)
	{
		return x == father[x] ? x : father[x] = find(father[x]);
	}

	int unite(int x, int y)
	{
		int fx = find(x), fy = find(y);
		if (fx != fy) {
			father[fx] = fy;
			return 1;
		}
		return 0;
	}

	int query(int x, int y)
	{
		return find(x) == find(y);
	}

    public:
	void run()
	{
		int ans = 0;
		for (int i = 0; i < m; i++) {
			cin >> rel[i][0] >> rel[i][1] >> rel[i][2];
		}
		sort(rel.begin(), rel.end(), [](const vector<int> &a, const vector<int> &b) { return a[2] > b[2]; });

		for (int i = 0, x, y, v; i < m; i++) {
			x = rel[i][0];
			y = rel[i][1];
			v = rel[i][2];

			if (query(x, y)) {
				ans = v;
				break;
			}

			if (ent[x]) {
				unite(y, ent[x]);
			} else {
				ent[x] = y;
			}

			if (ent[y]) {
				unite(x, ent[y]);
			} else {
				ent[y] = x;
			}
		}
                cout << ans << endl;
	}

    public:
	Main(int n, int m) : n(n), m(m), ent(n + 1, 0), father(n + 1, 0), rel(m, vector<int>(3, 0))
	{
		iota(father.begin(), father.end(), 0);
	}
};

int main()
{
	int n, m;
	cin >> n >> m;
	Main app(n, m);
	app.run();
	return 0;
}